// import router from "@/routers/index";
import { ButtonProps } from "@/components/ProTable/interface";
import { OperatorType } from "@/enums/enum";

export namespace Mod {
  /**
   * @description 自定义按钮事件，返回true表示继续执行后续逻辑；返回false表示终止处理
   */
  export const before = async (modId: string, btn: ButtonProps<any>, row: any) => {
    if (btn.operatorType === OperatorType.CUSTOM) {
      if (btn.code === "config") {
        window.location.href = getSystemUrl() + `#/mod/def/${row.mod_id}?modName=${row.mod_name}`;
        //await router.push({ path: `/mod/def/${row.mod_id}`, query: { modName: row.mod_name } });
        return false;
      } else if (btn.code === "flow") {
        window.open(`/ry/flow/index.html?machineId=${row.mod_id}`, "_blank");
        return false;
      }

      return true;
    }

    return true;
  };

  const getSystemUrl = () => {
    return window.location.href.split("#")[0];
  };
}
